##parameters=form, modelIdentity, repositoryIdentity

from Products.KnowledgeEngine.AssessmentFilter import AssessmentFilter

ass = context.knowledgeengine_assessmentstorageservice

uid = "%s_%s" % ( modelIdentity, repositoryIdentity )



try:
    query = form[ "search_" + uid ]
except KeyError:
    query = {}

repository = context.getComponentByIdentity( repositoryIdentity )
mapping = repository.getFilterOnMapping()

kerl = ['all']

#for index, value in query.items():
for clause in mapping:
    index   = clause['index']
    default = clause.get('default', None)    
        
    value = query.get( index, default )
    
    if value:
        kerl.append( ['idx:' + index, '=', value ] )
    
    
model = context.getComponentByIdentity( modelIdentity )

afilter = AssessmentFilter( "", kerl, model=model )

user = context.portal_membership.getAuthenticatedMember()

assessments = ass.getAssessmentsSatisfyingFilter( afilter, user )

return assessments